package jmine.tec.batch.builder;

import java.util.ArrayList;
import java.util.List;

import jmine.tec.batch.domain.MPhase;
import jmine.tec.batch.domain.MProcess;
import bancosys.tec.persist.builders.AbstractDBBuilder;

/**
 * Builder de MPhase.
 * 
 * @author Gallardo
 */
public class MPhaseBuilder extends AbstractDBBuilder<MPhase> {
    public static MPhaseBuilder criaMPhase() {
        return new MPhaseBuilder();
    }

    private String mnemonico = "MPHASE_MNEMONICO";

    private List<MProcess> processes = new ArrayList<MProcess>();

    /**
     * {@inheritDoc}
     */
    @Override
    public MPhase doBuild() {
        MPhase phase = this.createBean(MPhase.class);
        phase.setMnemonico(this.mnemonico);
        phase.setProcesses(this.processes);
        for (MProcess process : this.processes) {
            process.addPhase(phase);
        }
        return phase;
    }

    public MPhaseBuilder comMnemonico(String mnemonico) {
        this.mnemonico = mnemonico;
        return this;
    }

    public MPhaseBuilder comProcess(MProcess process) {
        this.processes.add(process);
        return this;
    }
}
